package com.ydd.util.db;

import android.content.Context;
import android.content.SharedPreferences;

import com.ydd.MyApplication;

/**
 * Created by tao on 17-3-17.
 */

public class SPManager {

    private static final String SHARED_PREFERENCE_NAME = "configure.db";

    public static final String VIDEO_SETTING = "video_setting";
    public static final String USER_NAME = "user_name";
    public static final String USER_PASSWORD = "user_password";
    public static final String USER_PHOTO_URL = "user_photo_url";

    /**
     * 上次基金更新时间
     */
    public static final String LAST_UPDATE_PRODUCT = "last_update_product";
    public static final String VIDEO_PLAY_SETTING = "video_play_setting";
    public static final String IS_SHOW_GUIDE = "is_show_guide";
    public static final String AUTOMATIC__LOGIN_USER = "automatic_login_user";
    public static final String REMEMBER_PASSWORD_USER = "remember_password_user";
    public static final String IS_LOGIN_USER = "is_login_user";

    private static SPManager mInstance = null;
    private static SharedPreferences sp = null;
    private static SharedPreferences.Editor editor = null;

    public static SPManager getInstance() {
        if (mInstance == null || sp == null || editor == null) {
            mInstance = new SPManager();
        }
        return mInstance;
    }

    private SPManager() {
        sp = MyApplication.getInstance().getSharedPreferences(SHARED_PREFERENCE_NAME,
                Context.MODE_PRIVATE);
        editor = sp.edit();
    }

    public static void putInt(String key, int value) {
        editor.putInt(key, value);
        editor.commit();
    }

    public static void putString(String key, String value) {
        editor.putString(key, value);
        editor.commit();
    }

    public static void putBoolean(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static int getInt(String key, int defaultValue) {
        return sp.getInt(key, defaultValue);
    }

    public static String getString(String key, String defaultValue) {
        return sp.getString(key, defaultValue);
    }

    public static boolean getBoolean(String key, boolean defaultValue) {
        return sp.getBoolean(key, defaultValue);
    }


}
